package net.pws.oos.web.dto;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import net.pws.common.beanutils.BeanUtils;
import net.pws.oos.biz.model.Notice;
import net.pws.oos.biz.model.User;

@SuppressWarnings("rawtypes")
public class NoticeDto extends Notice {
    
    private static final long serialVersionUID = 3492530614373160922L;
    
    public static NoticeDto from(Notice notice) {
        if (notice == null) {
            return null;
        }
        
        String[] ignoredProps = { "creator", "organ" };
        NoticeDto dto = new NoticeDto();
        BeanUtils.copyProperties(dto, notice, ignoredProps);
        User creator = notice.getCreator();
        if (creator != null) {
            dto.setCreatorId(creator.getId());
            dto.setCreatorName(creator.getName());
        }
        
        return dto;
    }
    
    public static NoticeDto from(Map map) {
        if (map == null) {
            return null;
        }
        
        NoticeDto dto = new NoticeDto();
        BeanUtils.copyProperties(dto, map);
        return dto;
    }
    
    public static List<NoticeDto> from(List<Map> maps) {
        List<NoticeDto> list = new ArrayList<NoticeDto>();
        for (Map map : maps) {
            list.add(from(map));
        }
        return list;
    }
    
    public static Notice to(NoticeDto dto) {
        Notice notice = new Notice();
        BeanUtils.copyProperties(notice, dto);
        return notice;
    }
    
    private int readCount;
    
    private int unreadCount;
    
    private Date readDate;
    
    private String creatorId;
    
    private String creatorName;
    
    private List<NoticeReceiverDto> readReceivers;
    
    private List<NoticeReceiverDto> unreadReceivers;
    
    public int getReadCount() {
        return readCount;
    }
    
    public void setReadCount(int readCount) {
        this.readCount = readCount;
    }
    
    public int getUnreadCount() {
        return unreadCount;
    }
    
    public void setUnreadCount(int unreadCount) {
        this.unreadCount = unreadCount;
    }
    
    public String getCreatorId() {
        return creatorId;
    }
    
    public void setCreatorId(String creatorId) {
        this.creatorId = creatorId;
    }
    
    public String getCreatorName() {
        return creatorName;
    }
    
    public void setCreatorName(String creatorName) {
        this.creatorName = creatorName;
    }

    public List<NoticeReceiverDto> getReadReceivers() {
        return readReceivers;
    }

    public void setReadReceivers(List<NoticeReceiverDto> readReceivers) {
        this.readReceivers = readReceivers;
    }

    public List<NoticeReceiverDto> getUnreadReceivers() {
        return unreadReceivers;
    }

    public void setUnreadReceivers(List<NoticeReceiverDto> unreadReceivers) {
        this.unreadReceivers = unreadReceivers;
    }

	public Date getReadDate() {
		return readDate;
	}

	public void setReadDate(Date readDate) {
		this.readDate = readDate;
	}
}
